#include "DmMainAfx.h"
#include "Blend.h"
#include "BlendInline.h"
#include "StretchTable.h"

#include <omp.h>
#include <mmintrin.h>
#include <xmmintrin.h>
#include <emmintrin.h>

extern DWORD StretchTable[(2<<8)+1];
extern const BYTE* ColorTable;

#define _MAKE_BLEND(mode, bits, stretch, simd) Blend##mode##bits##stretch##simd
#define _MAKE_BLENDCOLOR(mode, simd) Blend##mode##Color32##simd
#define _MAKE_GETPIXEL(bits) GetPixel##bits
#define _MAKE_GET2PIXEL(bits) Get2Pixel##bits##MMX
#define _MAKE_BLENDPIXEL(mode, simd) BlendPixel##mode##simd
#define _MAKE_BLEND2PIXEL(mode) Blend2Pixel##mode##MMX
#define _MAKE_BLEND4PIXEL(mode) Blend4Pixel##mode##MMX
#define _MAKE_BLENDPIXELSTRETCH(mode, bits, stretch, simd) BlendPixel##mode##bits##stretch##simd
#define _MAKE_BLENDBORDERSTRETCH(mode, bits, stretch, simd) BlendBorder##mode##bits##stretch##simd

#define MAKE_BLEND(mode, bits, stretch, simd) _MAKE_BLEND(mode, bits, stretch, simd)
#define MAKE_BLENDCOLOR(mode, simd) _MAKE_BLENDCOLOR(mode, simd)
#define MAKE_GETPIXEL(bits) _MAKE_GETPIXEL(bits)
#define MAKE_GET2PIXEL(bits) _MAKE_GET2PIXEL(bits)
#define MAKE_BLENDPIXEL(mode, simd) _MAKE_BLENDPIXEL(mode, simd)
#define MAKE_BLEND2PIXEL(mode) _MAKE_BLEND2PIXEL(mode)
#define MAKE_BLEND4PIXEL(mode) _MAKE_BLEND4PIXEL(mode)
#define MAKE_BLENDPIXELSTRETCH(mode, bits, stretch, simd) _MAKE_BLENDPIXELSTRETCH(mode, bits, stretch, simd)
#define MAKE_BLENDBORDERSTRETCH(mode, bits, stretch, simd) _MAKE_BLENDBORDERSTRETCH(mode, bits, stretch, simd)
#define MAKE_BLENDAREAAVERAGING32(mode, bits, simd) _MAKE_BLEND(mode, bits, AreaAveraging32, simd)
#define MAKE_BLENDAREAAVERAGING64(mode, bits, simd) _MAKE_BLEND(mode, bits, AreaAveraging64, simd)

namespace xRender
{

//Blend Src
#define BLEND_MODE Src

#define PIXEL_BITS 32
#include "BlendTemplate.h"
#include "BlendKeyColorTemplate.h"
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#include "BlendStretchAreaAveragingTemplate.h"
#include "BlendMMXTemplate.h"
#include "BlendKeyColorMMXTemplate.h"
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#include "BlendStretchAreaAveragingSSE2Template.h"
#undef PIXEL_BITS

#define PIXEL_BITS 24
#include "BlendTemplate.h"
#include "BlendKeyColorTemplate.h"
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#include "BlendStretchAreaAveragingTemplate.h"
#include "BlendMMXTemplate.h"
#include "BlendKeyColorMMXTemplate.h"
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#include "BlendStretchAreaAveragingSSE2Template.h"
#undef PIXEL_BITS

#define PIXEL_BITS 8
#include "BlendTemplate.h"
#include "BlendKeyColorTemplate.h"
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#include "BlendStretchAreaAveragingTemplate.h"
#include "BlendMMXTemplate.h"
#include "BlendKeyColorMMXTemplate.h"
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#include "BlendStretchAreaAveragingSSE2Template.h"
#undef PIXEL_BITS

#include "BlendColorTemplate.h"

#undef BLEND_MODE

//Blend SrcOver
#define BLEND_MODE SrcOver

#define PIXEL_BITS 32
#include "BlendTemplate.h"
#include "BlendAlphaTemplate.h"
#define BLENDALPHA
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#undef BLENDALPHA
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#include "BlendMMXTemplate.h"
#include "BlendAlphaMMXTemplate.h"
#define BLENDALPHA
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#undef BLENDALPHA
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#undef PIXEL_BITS

#define PIXEL_BITS 24
#include "BlendTemplate.h"
#include "BlendAlphaTemplate.h"
#define BLENDALPHA
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#undef BLENDALPHA
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#include "BlendMMXTemplate.h"
#include "BlendAlphaMMXTemplate.h"
#define BLENDALPHA
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#undef BLENDALPHA
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#undef PIXEL_BITS

#define PIXEL_BITS 8
#include "BlendTemplate.h"
#include "BlendAlphaTemplate.h"
#define BLENDALPHA
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#undef BLENDALPHA
#include "BlendStretchBilinearTemplate.h"
#include "BlendStretchBicubicTemplate.h"
#include "BlendMMXTemplate.h"
#include "BlendAlphaMMXTemplate.h"
#define BLENDALPHA
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#undef BLENDALPHA
#include "BlendStretchBilinearMMXTemplate.h"
#include "BlendStretchBicubicMMXTemplate.h"
#undef PIXEL_BITS

#include "BlendColorTemplate.h"
#include "BlendColorMMXTemplate.h"

#undef BLEND_MODE

//Blend Mul
#define BLEND_MODE Mul

#define PIXEL_BITS 32
#include "BlendTemplate.h"
#include "BlendMMXTemplate.h"
#undef PIXEL_BITS

#define PIXEL_BITS 24
#include "BlendTemplate.h"
#include "BlendMMXTemplate.h"
#undef PIXEL_BITS

#define PIXEL_BITS 8
#include "BlendTemplate.h"
#include "BlendMMXTemplate.h"
#undef PIXEL_BITS

#include "BlendColorTemplate.h"
#include "BlendColorMMXTemplate.h"

#undef BLEND_MODE

//Blend DstOver
#define BLEND_MODE DstOver

#define PIXEL_BITS 32
#include "BlendTemplate.h"
#include "BlendMMXTemplate.h"
#undef PIXEL_BITS

#define PIXEL_BITS 24
#include "BlendTemplate.h"
#include "BlendMMXTemplate.h"
#undef PIXEL_BITS

#define PIXEL_BITS 8
#include "BlendTemplate.h"
#include "BlendMMXTemplate.h"
#undef PIXEL_BITS

#include "BlendColorTemplate.h"
#include "BlendColorMMXTemplate.h"

#undef BLEND_MODE

//Blend Or
#define BLEND_MODE Or
#include "BlendColorTemplate.h"
#undef BLEND_MODE

//Blend Gray
#define BLEND_MODE Gray
#include "BlendColorTemplate.h"
#undef BLEND_MODE

}